import 'package:flutter/material.dart';
import './index_page.dart';
import 'package:provide/provide.dart';
// Provide
import './provide/counter.dart';
import './provide/child_category_provide.dart';
import './provide/category_goods_list_provide.dart';
import './provide/details_info_provide.dart';
import './provide/cart_provide.dart';
import './provide/test_provide.dart';
import './provide/current_index.dart';
// 路由插件
import 'package:fluro/fluro.dart';
// 
import './routers/router.dart';
import './routers/application.dart';

main(){
  var counter = Counter();
  var childCategory = ChildCategory();
  var categoryGoodsListProvied = CategoryGoodsListProvied();
  var dtailsProviedInfo = DetailsProviedInfo();
  var cartProvide = CartProvide();
  var testProvide = TestProvide();
  var currentIndexProvide = CurrentIndexProvide();
  var providers = Providers();
 
  // 依赖
  providers
      ..provide(Provider<Counter>.value(counter))
      ..provide(Provider<ChildCategory>.value(childCategory))
      ..provide(Provider<CategoryGoodsListProvied>.value(categoryGoodsListProvied))
      ..provide(Provider<DetailsProviedInfo>.value(dtailsProviedInfo))
      ..provide(Provider<CartProvide>.value(cartProvide))
      ..provide(Provider<TestProvide>.value(testProvide))
      ..provide(Provider<CurrentIndexProvide>.value(currentIndexProvide));
  runApp(ProviderNode(child:MyApp(),providers: providers,));
}

class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // 初始化路由
    final router = Router();
    Routes.configureRoutes(router);
    Application.router = router;
    
    return Container(
      child: MaterialApp(
        title: '百姓生活家',
        // 去掉dubuger
        debugShowCheckedModeBanner: false,
        // 将路由配置flutter 
        onGenerateRoute: Application.router.generator,
        theme: ThemeData(
          // 主题色
          primaryColor: Colors.pink,
        ),
        home:IndexPage()
      ),
    );
  }
}